package in.muton.edushare.pages.assignment;

import in.muton.edushare.EduShareSession;
import in.muton.edushare.pages.coursepages.CoursePage;
import in.muton.edushare.panels.assignment.EditAssignmentPanel;
import in.muton.edushare.url.EntityPageParams;
import in.muton.edushare.wicket.models.CayenneModel;

import org.apache.wicket.PageParameters;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.vo.Courses;

public class Edit extends AssignmentBase {

	private CayenneModel<Courses> courseModel;
	
	public Edit(PageParameters params) {
		super(params);
		courseModel = new CayenneModel<Courses>(getModel().getObject().getCourseInstance().getCourse());
		add(new EditAssignmentPanel("assnEditMain", getModel()){

			private static final long serialVersionUID = -2042420083901804926L;

			@Override
			public void afterPublished() {
				EduShareSession.get().setFeedbackMsg("Published successfully");
				setResponsePage(Detail.class, EntityPageParams.getParams(getModel()));
			}
			
			@Override
			public void afterCanceled() {
				setResponsePage(Detail.class, EntityPageParams.getParams(getModel()));
			}
			
			@Override
			public void afterUpdated() {
				setResponsePage(Detail.class, EntityPageParams.getParams(getModel()));
			}
			
			@Override
			public void afterDeleted() {
				setResponsePage(CoursePage.class, EntityPageParams.getParams(courseModel));
			}
		});
	}

	@Override
	protected String getActivePage() {
		return "assnEdit";
	}

	@Override
	public String getPageTitle() {
		return "Edit Assignment | " + getModel().getObject().getAssignmentTitle() +" | "+ApplicationConstants.APPLICATION_NAME;
	}

}
